from unicodedata import category
from sqlalchemy import VARCHAR, Column, BigInteger, Integer, String, Text
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class CmTask(Base):
    __tablename__ = 'cm_task'
    id = Column(BigInteger, primary_key=True, nullable=False, comment='id')
    create_time = Column(BigInteger, nullable=False, comment='创建时间')
    end_time = Column(BigInteger, nullable=True)
    state = Column(Integer, nullable=False, default=0, comment='0 排队中 1 处理中 2 成功 3失败')
    task_param = Column(Text, comment='参数')
    task_result = Column(Text, comment='处理结果')
    record_id = Column(BigInteger, nullable=False, comment='记录ID')
    task_type = Column(Integer, nullable=False, default=0, comment='1 同步 2 异步')

    def task_to_dict(self):
        return {k: v for k, v in self.__dict__.items() if not k.startswith('_')}


class CmRecord(Base):
    __tablename__ = 'cm_record'
    id = Column(BigInteger, primary_key=True, nullable=False, comment='id')
    category = Column(Integer, nullable=False, comment='分类 1 文件 2 商品')
    create_time = Column(BigInteger, nullable=False, comment='创建时间')
    end_time = Column(BigInteger, nullable=True)
    state = Column(Integer, nullable=False, default=0, comment='0 排队中 1 处理中 2 完全成功 3部分成功 4失败')
    record_name = Column(String, comment='参数')
    user_id = Column(BigInteger, nullable=False, comment='用户ID')

    def task_to_dict(self):
        return {k: v for k, v in self.__dict__.items() if not k.startswith('_')}
